<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置<small>日志管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>日志管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <template>
                <div class="filter-container">
                    <el-input placeholder="用户名称" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                    <span class="demonstration"></span>
                    <el-date-picker
                            v-model="timemap.startTime"
                            type="datetime"
                            placeholder="选择起始日期时间">
                    </el-date-picker>-
                    <span class="demonstration"></span>
                    <el-date-picker
                            v-model="timemap.endTime"
                            type="datetime"
                            placeholder="选择结束日期时间">
                    </el-date-picker>
                    <el-button @click="_findPage()" class="dalfBut">查询</el-button>
                </div>
            </template>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="msg" label="操作信息" align="center"></el-table-column>
                <el-table-column prop="in_time" label="起始时间" align="center"></el-table-column>
                <el-table-column prop="mod_time" label="结束时间" align="center"></el-table-column>
                <el-table-column prop="operator" label="操作人" align="center">
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    /*设置默认日期   昨天*/
    var pre = new Date();
    pre.setDate(pre.getDate()-1);
    var vue = new Vue({
        el: '#app',
        data:{
            timemap:{
                /*默认开始日期:去年今天*/
                startTime:pre,
                /*默认结束日期:今天*/
                endTime:new Date()
            },
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            backendUrl:"http://localhost:82"
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            _findPage(){
                if(this.pagination.queryString !=null && this.pagination.queryString.length>0){
                    this.pagination.currentPage = 1;
                }
                this.findPage();
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage:this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString:this.pagination.queryString
                };

                var date1 = this.formatDate(this.timemap.startTime.getFullYear(), this.timemap.startTime.getMonth() + 1, this.timemap.startTime.getDate(),this.timemap.startTime.getHours(),this.timemap.startTime.getMinutes(),this.timemap.startTime.getSeconds());

                var date2 = this.formatDate(this.timemap.endTime.getFullYear(), this.timemap.endTime.getMonth() + 1, this.timemap.endTime.getDate(),this.timemap.endTime.getHours(),this.timemap.endTime.getMinutes(),this.timemap.endTime.getSeconds());
                axios.defaults.withCredentials = true;
                axios.post(this.backendUrl+"/log/findPage.do?date1="+date1+"&date2="+date2,param).then((response)=>{
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                }).catch((err)=>{
                    this.showMessage(err)
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            showMessage(err){
                console.log(err);
                if(err == 'Error: Request failed with status code 403'){
                    this.$message({
                        type:"error",
                        message:"您的权限不足！！"
                    });
                }else{
                    this.$message({
                        type:"error",
                        message:"未知错误，请联系管理员！！"
                    });
                }
            },
            formatDate: function (year, month, day,hour,minute,second) {
                var y = year;

                var m = month;
                if (m < 10) m = "0" + m;
                var d = day;
                if (d < 10) d = "0" + d;
                var h = hour;
                if (h < 10) h = "0" + h;
                var M = minute;
                if (M < 10) M = "0" + M;
                var s = second;
                if (s < 10) s = "0" + s;
                return y + "-" + m + "-" + d +" " + h + ":" + M + ":" + s
            }
        }
    });

</script>
</html>